<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
	<title>商品品牌</title>
	<%@ include file="/static/include/head.jsp" %>
	<link href="${ctx }/static/bootstrap/summernote/summernote.css" rel="stylesheet" />
	<script src="${ctx }/static/bootstrap/summernote/summernote.min.js"></script>
	<script src="${ctx }/static/bootstrap/summernote/lang/summernote-zh-CN.js"></script>
</head>
<body>
<!-- 模态框（Modal） -->
<form id="inputForm" modelAttribute="brand" action="${ctx}/product/brand/save" method="post" class="form-horizontal" enctype="multipart/form-data">
	<!-- <div class="modal-content"> -->
		<!-- 
		<div class="modal-header">
			<button class="close" type="button" data-dismiss="modal">×</button>
			<h4 class="modal-title" id="myModalLabel">商品品牌维护</h4>
		</div>
		 -->
		<div class="modal-body">
            <!-- error message here -->
            <div id="messageBox" class="alert alert-warning hide"></div>
			<tags:message content="${message}"/>
            <c:if test="${param.type eq 'edit'}">
				<input type="hidden" id="id" name="id" value="${brand.id}" />
			</c:if>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">品牌名称:</label>
					<div class="col-xs-6">
						<input type="text" id="name" name="name" value="${brand.name}"
							   placeholder="品牌名称" class="form-control  required">
					</div>
				</div>
				<!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">品牌网址:</label>
					<div class="col-xs-6">
						<input type="text" id="url" name="url" value="${brand.url}"
							   placeholder="品牌网址" class="form-control  url">
					</div>
				</div>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">品牌logo:</label>
					<div class="col-xs-6">
						<input type="file" id="logoFile" name="logoFile" accept="image/gif,image/jpg,image/jpeg,image/bmp,image/png">
					</div>
				</div>
				<c:if test="${!empty brand.logo }">
				<!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right"></label>
					<div class="col-xs-6">
					<c:choose>
					<c:when test="${fn:startsWith(brand.logo, 'http')}">
						<img alt="" src="${brand.logo}" height="100px;">
					</c:when>
					<c:otherwise>
						<img alt="" src="${ctx }${brand.logo}" height="100px;">
					</c:otherwise>
					</c:choose>
					</div>
				</div>
				</c:if>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">详细说明:</label>
					<div class="col-xs-6">
						   <textarea id="brief" name="brief" class="form-control  summernote">${brand.brief}</textarea>
					</div>
				</div>
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal" onclick="javascript:returnList();">返回</button>
            <c:if test="${param.type ne 'view'}">
			<button type="submit" class="btn btn-primary" onclick="doSubmit()">提交更改</button>
			</c:if>
		</div>
	<!-- </div> -->
</form>
<script>
$(function(){
	$('.summernote').summernote({
		dialogsInBody: true,
        height: 150,
        lang: 'zh-CN',
		fontSizes: ['8', '9', '10', '11', '12', '14', '18', '24', '36','48','72']
    });
	$('body').on( "show.bs.modal", function() {
	    $('.summernote').summernote({
	        height: 150
	    });
	})
});

function doSubmit() {
    $("#inputForm").validate({
        submitHandler: function(form){
            form.submit();
        },
        errorContainer: "#messageBox",
        errorPlacement: function(error, element) {
            $("#messageBox").html('<div class="alert alert-danger">' +
				'<a href="#" class="close" data-dismiss="alert">&times;</a>' +
				'<strong>警告！</strong>输入有误，请进行一些更改。</div>');
            if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                error.appendTo(element.parent().parent());
            } else {
                error.insertAfter(element);
            }
        }
    });
}

function returnList(){
 	window.location.href = "${ctx}/product/brand";
}
</script>
</body>
</html>
